<?php
	class Question_topics extends CI_Model{

		function __construct(){
			parent::__construct();
		}


		function get_question_topic_list($limit = 0, $offset = 10, $conditions  = array()){
			$where = "status=1";
			if($conditions){
				if(!empty($conditions['name'])){
					$where .= " AND name LIKE '%{$conditions['name']}%'";
				}
				if(!empty($conditions['school_id'])){
					$where .= " AND school_id = '{$conditions['school_id']}'";
				}
			}
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}question_topics WHERE $where ORDER BY id DESC ";
			if($limit > 0 || $offset > 0){
				$sql .= "LIMIT $limit, $offset";
			}
			$result = $this->db->query($sql)->result_array();
			$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
			return array("count" => $row_num['row_num'], "result" => $result);
		}

		function add_question_num($id){
			$sql = "UPDATE {$this->db->dbprefix}question_topics SET question_num = question_num + 1 WHERE id = $id";
			$this->db->query($sql);
		}

	}
